﻿@{
    ViewData["Title"] = "意见反馈列表";
    Layout = "~/Views/Shared/_LayoutNone.cshtml";
}
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">反馈类型:</label>
                    <div class="layui-input-inline">
                        <select id="type_id" name="type_id">
                            <option value="">选择反馈类型</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">姓名:</label>
                    <div class="layui-input-inline">
                        <input type="text" id="feedback_name" name="feedback_name" maxlength="50" placeholder="请输入姓名" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">Email:</label>
                    <div class="layui-input-inline">
                        <input type="text" id="feedback_email" name="feedback_email" maxlength="50" placeholder="请输入Email" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn" lay-submit lay-filter="LAY-app-contlist-search">
                        查询
                    </button>
                    <button class="layui-btn layui-btn-primary" lay-submit lay-filter="LAY-app-contlist-reset">重置</button>
                    <label style="margin-left: 10px; color: #6eae21; cursor: pointer;" id="collapse">展开<i style="right: -20px;" class="layui-icon layui-icon-down"></i></label>
                </div>
            </div>
            <div class="layui-form-item collapse_item" style="display:none;">
                <div class="layui-inline">
                    <label class="layui-form-label">联系电话:</label>
                    <div class="layui-input-inline">
                        <input type="text" id="feedback_phone" name="feedback_phone" maxlength="50" placeholder="请输入联系电话" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">反馈内容:</label>
                    <div class="layui-input-inline">
                        <input type="text" id="feedback_content" name="feedback_content" placeholder="请输入反馈内容" autocomplete="off" class="layui-input">
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">提交日期:</label>
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input time" id="created_at" name="created_at" placeholder="选择提交日期" autocomplete="off">
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <div class="layui-form-item" style="margin-bottom: 5px;">
                <div class="layui-inline">
                    <button class="layui-btn layui-btn-sm layuiadmin-btn-list" data-type="add"><i class="layui-icon layui-icon-add-1"></i>新增意见反馈</button>
                </div>
                <div class="layui-inline">
                    <button class="layui-btn layui-btn-sm layuiadmin-btn-list" data-type="export"><i class="layui-icon layui-icon-export"></i>导出意见反馈</button>
                </div>
            </div>
            <table id="LAY-app-content-list" lay-filter="LAY-app-content-list"></table>
            <blockquote class="layui-elem-quote" style="margin: 10px 0; padding: 10px">
                <div>
                    <strong>意见反馈说明：</strong>
                    此功能主要用于APP/小程序/PC等前端手机用户反馈的信息，方便后续针对系统各方面功能进行升级。
                </div>
            </blockquote>

            <script type="text/html" id="table-content-list">
                <a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
            </script>
        </div>
    </div>
</div>

<script src="~/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/layuiadmin/'
    }).extend({
        index: '/lib/index'
    }).use(['index', 'table', 'laydate', 'util'], function () {
        var $ = layui.$
            , table = layui.table
            , admin = layui.admin
            , form = layui.form
            , laydate = layui.laydate
            , util = layui.util;

        var num = 2;

        lay('.time').each(function () {
            laydate.render({
                elem: this,
                range: true
            });
        });

        // 默认加载
        $(function () {
            loading = layer.load(2, {
                shade: [0.2, '#000']
            });

            // 意见类型
            admin.req({
                url: '/feedbacktypes/select'
                , done: function (res_typeid) {
                    layer.close(loading);
                    $.each(res_typeid.data, function (i, item) {
                        $("#type_id").append("<option value=\"" + res_typeid.data[i].type_id + "\">" + res_typeid.data[i].type_name + "</option>");
                    });
                    layui.form.render('select');
                }
            });
        });

        // 加载表格数据
        table.render({
            elem: "#LAY-app-content-list",
            url: "/feedback/list",
            toolbar: false,
            cols: [
                [
                    {
                        type: "numbers",
                        title: "序号",
                        width: 80
                    },
                    {
                        field: "type_name",
                        title: "反馈类型",
                        width: 150
                    },
                    {
                        field: "feedback_name",
                        title: "姓名",
                        width: 150
                    },
                    {
                        field: "feedback_email",
                        title: "Email",
                        width: 150
                    },
                    {
                        field: "feedback_phone",
                        title: "联系电话",
                        width: 150
                    },
                    {
                        field: "feedback_content",
                        title: "反馈内容",
                        minWidth: 200
                    },
                    {
                        field: "format_time",
                        title: "提交日期",
                        sort: !0,
                        width: 200
                    },
                    {
                        title: "操作",
                        width: 200,
                        align: "center",
                        fixed: "right",
                        toolbar: "#table-content-list"
                    }]
            ],
            page: !0,
            limit: 10,
            limits: [10, 20, 50, 200, 500]
        }),

        // 右侧操作事件
        table.on("tool(LAY-app-content-list)", function (t) {
            var feedback_id = t.data.feedback_id;
            if ("del" === t.event) {
                layer.confirm("确定删除此意见反馈？", function (e) {
                    admin.req({
                        headers: {
                            'RequestVerificationToken': csrfToken
                        },
                        method: 'POST',
                        url: '/feedback/delete/' + feedback_id
                        , done: function (res) {  
                            t.del();
                            layer.close(e);
                        }
                    });
                });
            }
            else if ("edit" === t.event) {
                layer.open({
                    type: 2,
                    title: "编辑意见反馈-" + feedback_id,
                    content: "/feedback/edit?id=" + feedback_id,
                    maxmin: !0,
                    area: ["550px", "550px"],
                    btn: ["确定", "取消"],
                    yes: function (e, i) {
                        a = i.find("iframe").contents().find("#layuiadmin-app-form-edit");
                        a.trigger("click");
                    }
                })
            }
        }),

        // 监听搜索
        form.on('submit(LAY-app-contlist-search)', function (data) {
            var field = data.field;
            table.reload('LAY-app-content-list', {
                where: field,
                page: {
                    curr: 1
                }
            });
        });

        // 监听重置
        form.on('submit(LAY-app-contlist-reset)', function (data) {
            $(".layui-form input").val("");
            $(".layui-card-header select").val("");
        });

        var $ = layui.$, active = {
            add: function () {
                layer.open({
                    type: 2
                    , title: '添加意见反馈'
                    ,content: '/feedback/create'
                    ,maxmin: true
                    ,area: ['550px', '550px']
                    ,btn: ['确定', '取消']
                    ,yes: function(index, layero){
                        //点击确认触发 iframe 内容中的按钮提交
                        var submit = layero.find('iframe').contents().find("#layuiadmin-app-form-submit");
                        submit.click();
                    }
                });
            },
            export: function () {
                loading = layer.load(2, {
                    shade: [0.2, '#000']
                });

                admin.req({
                    headers: {
                        'RequestVerificationToken': csrfToken
                    },
                    method: 'POST',
                    data: { "type_id": $("#type_id").val(), "feedback_name": $("#feedback_name").val(), "feedback_email": $("#feedback_email").val(), "feedback_phone": $("#feedback_phone").val(), "feedback_content": $("#feedback_content").val(), "select_date": $("#created_at").val() },
                    url: '/excel/exportfeedback'
                    , done: function (res) {
                        layer.close(loading);
                        if (res.errcode) {
                            layer.open({
                                title: '错误提示'
                                , type: 1
                                , content: '<div style="color: red; padding: 20px;">' + res.errcode + ':' + res.errmsg + '</div>'
                                , btn: ["确定"]
                            });
                        } else if (res.code == 0 && res.count == 0) {
                            layer.msg(res.msg, {
                                offset: '15px'
                                , icon: 1
                                , time: 2000
                            });
                        } else {
                            location.href = res.path;
                        }
                    }
                });
            },
            refresh: function () {
                table.reload('LAY-app-content-list');
            }
        };

        $('.layui-btn.layuiadmin-btn-list').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $('#collapse').on('click', function () {
            if (num % 2) {
                $(".collapse_item").hide();
                $("#collapse").html("展开<i style=\"right: -20px;\" class=\"layui-icon layui-icon-down\"></i>");
            }
            else {
                $(".collapse_item").show();
                $("#collapse").html("收起<i style=\"right: -20px;\" class=\"layui-icon layui-icon-up\"></i>");
            }
            num++;
        });
    });
</script>
